<template>
  <div>
    <van-row style="padding-top: 1rem;padding-bottom: 1rem">
      <van-col span="12">
        <table>
          <tr>
            <th>任务id</th>
            <th>我的任务</th>
          </tr>
          <tr v-for="(i,j) in tasklist" :key="j" @click="taskquery(i.id)">
            <td>{{j+1}}</td>
            <td>{{i.title}}</td>
          </tr>
        </table>
      </van-col>
      <van-col span="12" v-if="info!='x'">
        <table>
          <tr>
            <th>任务id</th>
            <th>任务名称</th>
            <th>审批人编号</th>
            <th>审批内容</th>
          </tr>
          <tr>
            <td>{{info.id}}</td>
            <td>{{info.title}}</td>
            <td>{{info.approver}}</td>
            <td><span v-for="(i,j) in info.params" :key="i.id"><font color="#00008b">{{j}}</font>:{{i}}&nbsp;</span></td>
          </tr>
        </table>
        审批意见：<van-field v-model="reason" />
        <van-button @click="taskok">批准</van-button>&nbsp;<van-button @click="taskno">退回</van-button>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import myaxios from "../../../https/myaxios";
// import bus from "../../../https/bus";
// import app1 from "../../../https/bus";
export default {
  name: "mytask",
  data(){
    return{
      tasklist:[],
      info:'x',
      count:0,
      username:localStorage.getItem("username"),
      userid:localStorage.getItem("userid"),
      reason:'',
      taskid:'',
    }
  },
  methods:{
    taskok(){
      this.count--
      // alert(this.count)
      // this.$emit("change",this.count)
      // bus.$emit("count",this.count)
      // app1.$emit("count",this.count)
      localStorage.setItem("count",this.count)
      // myaxios("taskok?userid="+localStorage.getItem("userid"),"get").then(res=>{
      //   alert(res.msg)
      // })
      let data = new FormData()
      data.append("taskid",this.taskid)
      data.append("username",this.username)
      data.append("userid",this.userid)
      data.append("reason",this.reason)
      data.append("agree","1")
      myaxios("taskrecordM","post",data).then(res=>{
        alert(res.code)
      })

    },
    taskno(){
      this.count--
      // alert(this.count)
      // this.$emit("change",this.count)
      // bus.$emit("count",this.count)
      // app1.$emit("count",this.count)
      localStorage.setItem("count",this.count)
      let data = new FormData()
      data.append("taskid",this.taskid)
      data.append("username",this.username)
      data.append("userid",this.userid)
      data.append("reason",this.reason)
      data.append("agree","2")
      myaxios("taskrecordM","post",data).then(res=>{
        alert(res.code)
      })

    },
    taskquery(val){
      this.taskid = val
      myaxios("taskquery?taskid="+val,"get").then(res=>{
        this.info=res.list
        this.info["params"]=JSON.parse(res.list["params"])
      })
    },
    gettask(){
      myaxios("mytask?userid="+localStorage.getItem("userid"),"get").then(res=>{
        this.tasklist=res.list
        this.count=res.list.length
        localStorage.setItem("count",this.count)
        // alert(this.count)
        // for(let i=0;i<this.tasklist.length;i++){
        //   this.tasklist[i]["title"] = JSON.parse(this.tasklist[i]["title"])
        // }

      })
    },
  },
  mounted() {
    this.gettask()
  }
}
</script>

<style scoped>

</style>